import { Modal } from "antd";
import DynamicQueryTable, { SelectionType } from "@/components/report/DynamicQueryTable";
import { useState } from "react";
import type { EamEquipment } from "@/pages/eam/equipment/entity";

interface SingleEquipmentSelectorProps {
	open: boolean;
	onCancel: () => void;
	onOk: (selectedEquipment?: EamEquipment) => void;
}

const SingleEquipmentSelector:React.FC<SingleEquipmentSelectorProps> = ({ open, onCancel, onOk }) => {
  
  // 选中的设备
  const [selectedEquipment, setSelectedEquipment] = useState<EamEquipment>();

  const handleOk = () => {
		onOk(selectedEquipment);
	};

	return (
		<Modal title="选择设备" open={open} onCancel={onCancel} onOk={handleOk} width={800} destroyOnClose>
			<DynamicQueryTable 
        reportCode="equipment_select_report"
        selectionType={SelectionType.RADIO}
        onSelectChange={(selectedRows) => {setSelectedEquipment(selectedRows[0])}}  
      />
		</Modal>
	);
}

export default SingleEquipmentSelector;